package com.hs.jhzd.repository;

import com.hs.jhzd.entity.Questionnaire;
import com.hs.jhzd.entity.dto.QuestionnaireDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface QuestionnaireRepository extends JpaRepository<Questionnaire, String> {

    public List<Questionnaire> findAllByPrisonId(@Param("prisonId") String prisonId);

    public Questionnaire findQuestionnaireById(String id);

    public Integer countQuestionnaireById(String id);

    @Query(value="select id from jh_Questionnaire order by id DESC limit  1",nativeQuery=true)
    String findZybh();
    @Query("select  new com.hs.jhzd.entity.dto.QuestionnaireDto(u.id,u.prisonId,u.name, u.surveyType, u.createTime) from Questionnaire u where u.prisonId=:jsbh")
    List<QuestionnaireDto> findByPrisonId(@Param("jsbh") String jsbh);

    @Query("select u from Questionnaire u where u.id=:id")
    Optional<Questionnaire> findOneById(@Param("id")String id);
}
